// integral.js
//index.js  
//获取应用实例  
var app = getApp()
Page({
    data: {        
        winWidth: 0,
        winHeight: 0,
        //tab切换
        currentTab: 0,
        dates: '2016-11-08',
        date:'2016-11-08',
        index: 0,
        intro:'',
        p:1,
        list:[],
        start:'',
      endtime:''
    },
    onLoad: function () {
      var that = this
      var app = getApp()
      var that = this;
      var uid = wx.getStorageSync('uid');
      wx.request({
        url: app.globalData.host + '&g=App&m=User&a=my_score',
        data: {
          // id: that.data.options.id,
          uid: uid,
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res.data)
          that.setData({
            intro: res.data.intro,
          })
        }
      })

      that.setData({
        isHide: true,
        // options: options
      })
        /** 
         * 获取系统信息 
         */
        wx.getSystemInfo({

            success: function (res) {
                that.setData({
                    winWidth: res.windowWidth,
                    winHeight: res.windowHeight
                });
            }

        });
    },
    /** 
       * 滑动切换tab 
       */
    bindChange: function (e) {

        var that = this;
        that.setData({ currentTab: e.detail.current });

    },
    /** 
     * 点击tab切换 
     */
    swichNav: function (e) {

        var that = this;

        if (this.data.currentTab === e.target.dataset.current) {
            return false;
        } else {
            that.setData({
                currentTab: e.target.dataset.current
            })
        }
    },
    //  点击日期组件确定事件  
    bindDateChange: function (e) {
        console.log(e.detail.value)
        this.setData({
          start: e.detail.value,
          p:1,
          list:[]
        })
        this.getlist();
    },
    bindDateChanges: function (e) {
      console.log(e.detail.value)
      this.setData({
        endtime: e.detail.value,
        p: 1,
        list: []
      })
      this.getlist();
    },
    onShow:function(){
      var app = getApp()
      var that = this;
      var uid = wx.getStorageSync('uid');
      wx.request({
        url: app.globalData.host + '&g=App&m=User&a=my_score',
        data: {
          // id: that.data.options.id,
          uid: uid,
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res.data)
          that.setData({
            //list:res.data.list,
            score:res.data.score,
            start: res.data.start_time,
            endtime: res.data.end_time
          })
        }
      })
      that.getlist();
    },
    getlist: function () {
      var app = getApp()
      var that = this;
      var uid = wx.getStorageSync('uid');  
      wx.request({
        url: app.globalData.host + '&g=App&m=User&a=my_score',
        data: {
          uid: uid,
          p: that.data.p,
          start_time: that.data.start,
          end_time: that.data.endtime,
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          if (res.data.status == 1) {
            var list = that.data.list
            console.log(res.data)
            // console.log(res.data.list.length)
            var ol = list.length
            for (var i = 0; i < res.data.page.dataNow; i++) {
              list[ol + i] = res.data.list[i];
            }
            console.log(res.data)       
            //var winh = 200   
           // ol = list.length
           // winh = winh + ol*70
            that.setData({
              p: that.data.p + 1,
              list: list,
              //winHeight: winh
            })
          }
        }
      })
      that.setData({
        isHide: 1,
      })
      wx.hideNavigationBarLoading()
    },
    onReachBottom: function () {
      console.log('--------下拉刷新-------')
      wx.showNavigationBarLoading() //在标题栏中显示加载
      this.getlist();
    },
}) 